﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    [ScriptType("SP.FeatureCollection", ServerTypeId="{8b9c0015-193d-4062-8e98-8d23c303eedd}")]
    public class FeatureCollection : ClientObjectCollection<Feature>
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public FeatureCollection(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public Feature Add(Guid featureId, bool force, FeatureDefinitionScope featdefScope)
        {
            Feature feature = new Feature(base.Context, new ObjectPathMethod(base.Context, base.Path, "Add", new object[] { featureId, force, featdefScope }));
            feature.Path.SetPendingReplace();
            ObjectIdentityQuery query = new ObjectIdentityQuery(feature.Path);
            base.Context.AddQueryIdAndResultObject(query.Id, feature);
            base.Context.AddQuery(query);
            base.AddChild(feature);
            return feature;
        }

        [Remote]
        public Feature GetById(Guid featureId)
        {
            Dictionary<Guid, Feature> dictionary;
            object obj2;
            if (base.ObjectData.MethodReturnObjects.TryGetValue("GetById", out obj2))
            {
                dictionary = (Dictionary<Guid, Feature>) obj2;
            }
            else
            {
                dictionary = new Dictionary<Guid, Feature>();
                base.ObjectData.MethodReturnObjects["GetById"] = dictionary;
            }
            Feature feature = null;
            if (!dictionary.TryGetValue(featureId, out feature))
            {
                feature = new Feature(base.Context, new ObjectPathMethod(base.Context, base.Path, "GetById", new object[] { featureId }));
                dictionary[featureId] = feature;
            }
            return feature;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (flag)
            {
                return flag;
            }
            return flag;
        }

        [Remote]
        public void Remove(Guid featureId, bool force)
        {
            ClientAction query = new ClientActionInvokeMethod(this, "Remove", new object[] { featureId, force });
            base.Context.AddQuery(query);
        }
    }
}

